package com.clock.ui.activity;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;

import com.clock.photowall.R;
import com.clock.ui.fragment.CustomUIFragment;
import com.clock.ui.fragment.CustomViewFragment;
import com.clock.ui.fragment.FramesFragment;

public final class MainActivity extends BaseFragmentActivity implements OnCheckedChangeListener{

	RadioGroup menuGroup;
	RadioButton  custom_ui_menu , custom_frames_menu , custom_view_menu;
	TextView tv_title;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		this.initView();
	}
	
	private void initView(){
		menuGroup = (RadioGroup) findViewById(R.id.rg_bottom_menu);
		custom_ui_menu = (RadioButton) findViewById(R.id.rb_ui);
		custom_frames_menu = (RadioButton) findViewById(R.id.rb_frame);
		custom_view_menu = (RadioButton) findViewById(R.id.rb_view);
		tv_title = (TextView) findViewById(R.id.tv_main_title);
		menuGroup.setOnCheckedChangeListener(this);
		custom_ui_menu.setChecked(true);
	}

	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {
		if (group == menuGroup) {
			FragmentTransaction transaction = fragmentManager.beginTransaction();
			if (R.id.rb_frame == checkedId) {
				//tv_title.setText(custom_frames_menu.getText());
				setTitle(custom_frames_menu.getText());
				transaction.replace(R.id.fl_main_content, new FramesFragment());
			} else if (R.id.rb_ui == checkedId) {
				//tv_title.setText(custom_ui_menu.getText());
				setTitle(custom_ui_menu.getText());
				transaction.replace(R.id.fl_main_content, new CustomUIFragment());
			} else if (R.id.rb_view == checkedId) {
				//tv_title.setText(custom_view_menu.getText());
				setTitle(custom_view_menu.getText());
				transaction.replace(R.id.fl_main_content, new CustomViewFragment());
			}
			transaction.commit();
		}
	}
}
